package com.gu.controller.front;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gu.entity.EduCourse;
import com.gu.entity.vo.front.CourseFrontVo;
import com.gu.service.EduCourseService;
import com.gu.service.EduSubjectService;
import entity.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Description:
 *
 * @Autor: Rolin
 * datetime: 06-15-18:27
 */
@RestController
@Api(tags = "课程前台网页")
@CrossOrigin
@RequestMapping("/eduService")
public class CourseFrontController {

    @Resource
    private EduCourseService eduCourseService ;

    @ApiOperation("分页条件获取所有课程视频")
    @PostMapping ("front/getAllCourseList/{current}")
    public CommonResult getAllCourseList(@PathVariable("current")String current,
                                         @RequestBody(required = false)CourseFrontVo courseFrontVo){
        Page<EduCourse> page = eduCourseService.getCourseListFront(current,courseFrontVo);
        List<EduCourse> courseList = page.getRecords();
        List<CourseFrontVo> list = new ArrayList<CourseFrontVo>();
        //总页数
        long pages = page.getPages();
        //总条数
        long total = page.getTotal();
        courseList.forEach(course -> {
            CourseFrontVo courseFront= new CourseFrontVo();
            BeanUtils.copyProperties(course, courseFront);
            list.add(courseFront);
        });
        return CommonResult.success().data("totalPages",pages).data("totalRecords",total).data("courseList",list);

    }

}
